package com.sikeda.imagecomposetool;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.sikeda.imagecomposetool.adapter.GridPhotoViewAdapter;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2016/12/19.
 */

public class ImageComposedActivity extends AppCompatActivity {
    private RecyclerView rv_grid_photoviews;
    private List<String> list;
    private GridPhotoViewAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_composed);

        rv_grid_photoviews = (RecyclerView) findViewById(R.id.rv_grid_photoviews);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        rv_grid_photoviews.setLayoutManager(gridLayoutManager);
        adapter = new GridPhotoViewAdapter(this);
        rv_grid_photoviews.setAdapter(adapter);
        list = new ArrayList<>();
        getIntentData();
        adapter.setCustomItemOnClickListener(new GridPhotoViewAdapter.CustomItemOnClickListener() {
            @Override
            public void setOnItemClickListener(int pos) {
                startActivity(new Intent(ImageComposedActivity.this, PhotoViewActivity.class).putExtra("path", list.get(pos)));
            }
        });

    }

    public void getIntentData() {
        list = getIntent().getStringArrayListExtra("photos");
        if (list != null && list.size() != 0) {
            adapter.setData(list);
            adapter.notifyDataSetChanged();
        }
    }
}
